<template>
	<view class="my">

	<view class="my_top">
			<view class="my_top_info" @click="LinkInfo">
				<view style="display: flex;align-items: center;width: 95%;">
					<view class="my_top_info_src flex">
						<image src="../../static/mor.png" class="bfbimages" v-if="Info==''"></image>
						<image :src="Info.avatar" class="bfbimages" v-else></image>
					</view>
					<view class="my_top_info_tet">
						<view>
							<text v-if="Info==''">请登录</text>
							<text v-else>{{Info.nickname}}</text>
							<text
								style="font-size: 26rpx;font-weight: 500;color: #FE532B;display: inline-block;margin-left: 20rpx;" v-if="Info.is_merchant==1">已实名认证</text>
						</view>
						<view>
							<view class="ID" v-if="Info==''">未登录</view>
							<view class="ID" v-else>ID：{{Info.id}}</view>
							
							<view class="JF" v-if="Info==''">用户积分：0</view>
							<view class="JF" v-else>用户积分：{{Info.credit_nums}}</view>
						</view>
					</view>
				</view>
				<view class="flex">
					<image src="../../static/right.png" class="bfbimages"></image>
				</view>
			</view>

			<view class="my_bto">
				<view class="my_bto_one">
					<text style="font-size: 22rpx;color: #FFF0C1;">账户余额（￥）</text>
					<view style="display: flex;align-items: center;justify-content: flex-end;" @click="Linkwallet">
						<text>进入钱包</text>
						<view class="my_bto_one_icon flex">
							<image src="../../static/bai_right.png" class="bfbimages"></image>
						</view>
					</view>
				</view>
				<view class="my_bto_two">
					<text v-if="Info==''">0.00</text>
					<text v-else>{{Info.balance}}</text>
					<view style="display: flex;align-items: center;justify-content: flex-end;">
						<view class="my_bto_two_btn" @click="LinkRecharge">充值</view>
						<view class="my_bto_two_btn" style="background-color:#FBE1B0;color: #FE4925;"
							@click="LinkWithdrawal">提现</view>
					</view>
				</view>
			</view>
		</view>

		<view class="my_box">
			<view class="my_box_hb" @click="HBJL">
				<view class="my_box_hb_box">
					<view>
						<view class="my_box_hb_box_hb flex">
							<image src="../../static/hongbao.png" class="bfbimages"></image>
						</view>
						<text>抢包记录</text>
					</view>
					<view>
						<text style="display: inline-block;margin-bottom: 8rpx;">未使用<text
								style="font-size: 34rpx;color: #FE4725;">{{Info.user_activity_nums}}</text>个</text>
						<view class="my_box_hb_box_hb1 flex">
							<image src="../../static/hei_right.png" class="bfbimages"></image>
						</view>
					</view>
				</view>
			</view>

			<view class="my_box_dian" v-if="token">
				<view class="my_box_dian_men">
					<view>
						<view class="my_box_dian_men_src flex">
							<image :src="ShangJiaInfo.merchant_avatar" class="bfbimages" v-if="Info.is_merchant!=='0'"></image>
							<image src="../../static/my/sjno.png" class="bfbimages" v-if="Info.is_merchant=='0'"></image>
						</view>
						<text v-if="Info.is_merchant!=='0'">{{ShangJiaInfo.merchant_name}}</text>
						<text style="color: #999999;" v-if="Info.is_merchant=='0'">未完善</text>
						<view class="my_box_dian_men_xian" v-if="Info.is_merchant!=='0'">
							<view class="flex">
								<image src="../../static/rz.png" class="bfbimages"></image>
							</view>
							<text>企业认证</text>
						</view>
					</view>
					<view @click="LinkShangJiaInfo">
						<text>商家信息</text>
						<view class="my_box_dian_men_right flex">
							<image src="../../static/hei_right.png" class="bfbimages"></image>
						</view>
					</view>
				</view>

				<view class="my_box_dian_two">
					<view>
						<text>商家积分:<text style="color: #FE4725;" v-if="Info.is_merchant!=='0'">{{ShangJiaInfo.credit_nums}}</text><text style="color: #FE4725;" v-if="Info.is_merchant=='0'">0</text></text>
					</view>
					<view>
						<text>规则</text>
						<view
							style="width: 24rpx;height: 24rpx;text-align: center;line-height: 24rpx;margin-left: 8rpx;"
							class="flex">
							<image src="../../static/wenhao.png" class="bfbimages"></image>
						</view>
					</view>
				</view>

				<view class="my_box_dian_therr" v-for="(item,index) in 4" :key="index" @click="LinkShangJiaInfo">
					<view style="width: 40rpx;height: 40rpx;text-align: center;line-height: 40rpx;" class="flex">
						<image src="../../static/or_jia.png" class="bfbimages"></image>
					</view>
					<text style="display: inline-block;margin-right: 20rpx;">创建新的</text>
					<text style="display: inline-block;margin-right: 20rpx;" v-if="index==0">发红包</text>
					<text style="display: inline-block;margin-right: 20rpx;" v-if="index==1">优惠券</text>
					<text style="display: inline-block;margin-right: 20rpx;" v-if="index==2">邀约红包</text>
					<text style="display: inline-block;margin-right: 20rpx;" v-if="index==3">折扣红包</text>
					<view style="display: flex;align-items: center;margin-left: 20rpx;">
						<view
							style="width: 28rpx;height: 28rpx;margin-right: 8rpx;text-align: center;line-height: 28rpx;">
							<image src="../../static/red_wenhao.png" class="bfbimages"></image>
						</view>
						<text>规则</text>
					</view>
					<text>
						进行中
						<text style="color: #FE4725;font-size: 24rpx;" v-if="index==0">{{Info.red_envelope_count}}</text>
						<text style="color: #FE4725;font-size: 24rpx;" v-if="index==1">{{Info.coupon_count}}</text>
						<text style="color: #FE4725;font-size: 24rpx;" v-if="index==2">{{Info.invite_count}}</text>
						<text style="color: #FE4725;font-size: 24rpx;" v-if="index==3">{{Info.discount_count}}</text>
						个
					</text>
					<view style="width: 17rpx;height: 23rpx;text-align: center;line-height: 23rpx;" class="flex">
						<image src="../../static/hei_right.png" class="bfbimages"></image>
					</view>

				</view>
			</view>


			<view class="my_box_dian" style="padding-top:1rpx;padding-bottom: 30rpx;">
				<view class="my_box_dian_list" v-for="(item,index) in ListFor" :key="index" @click="Cgn(item)">
					<view>
						<view class="my_box_dian_list_src flex">
							<image :src="item.icon" class="bfbimages"></image>
						</view>
						<text>{{item.name}}</text>
					</view>
					<view class="flex">
						<image src="../../static/hei_right.png" class="bfbimages"></image>
					</view>
				</view>
				<view style="width: 100%;height: 30rpx;"></view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				ListFor: [{
						name: '店员管理',
						icon: '../../static/my/list1.png'
					},
					{
						name: '扫码核销',
						icon: '../../static/my/list2.png'
					},
					{
						name: '首页广告投放',
						icon: '../../static/my/list3.png'
					},
					{
						name: '意见反馈',
						icon: '../../static/my/list4.png'
					}
				],
				Info:'',
				ShangJiaInfo:'',
				token:false

			}
		},
		onShow() {
			this.InfoApi()
			if(uni.getStorageSync('token')){
				this.token=true
			}
		},
		methods: {
			InfoApi(){
				const token = uni.getStorageSync('token'); // 请根据实际情况获取 token
				uni.request({
					url:this.$uts + '/api/user/getUser',
					method:'POST',
					header:{
						'Authorization':`${'Bearer'} ${token}`,
						'server':1,
						'token':uni.getStorageSync('token')
					},
					success:res=>{
						console.log(res.data.data,'个人信息');
						this.Info=res.data.data
						
						uni.setStorageSync('is_merchant',this.Info.is_merchant) //是否为商家 0不是 1是
						
						if(res.data.data.is_merchant=='1'){
							this.ShangJiaInfoApi()
							console.log('请求了商家接口');
						}else{
							console.log('未请求商家接口');
						}
						
					}
				})
			},
			ShangJiaInfoApi(){
				this.$request('/api/merchant/merchantInfo').then((res)=>{
					console.log(res.data,'商家信息');
					this.ShangJiaInfo=res.data
				})
			},
			HBJL(){
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				uni.navigateTo({
					url:'/pages/RedEnvelope/RedEnvelope'
				})
			},
			LinkShangJiaInfo() {
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				
				
				if(this.Info.is_merchant=='0'){  //不是商家
					uni.navigateTo({
						url: '/TUIKit/Merchant/ShangJiainfo_Set'
					});
				}else{
					uni.navigateTo({
						url: '/TUIKit/Merchant/ShangJiainfo'
					})
				}
				
			},
			LinkInfo() {
				if(!uni.getStorageSync('token')){
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}else{
					uni.navigateTo({
						url: '/pages/info/info'
					})
				}
				
			},
			Cgn(item) {
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				
				if (item.name == '店员管理') {
					uni.navigateTo({
						url: '/pages/Sm/Sm'
					})
				} else if (item.name == '扫码核销') {
					uni.navigateTo({
						url: '/pages/WriteOff/WriteOff'
					})
				} else if (item.name == '首页广告投放') {
					uni.navigateTo({
						url:'/pages/launch/launch'
					})
					// uni.navigateTo({
					// 	url:'/pages/AboutUs/AboutUs'
					// })
				} else if (item.name == '意见反馈') {
					uni.navigateTo({
						url: '/pages/opinion/opinion'
					})
				}
			},
			LinkRecharge() {
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				
				uni.navigateTo({
					url: '/pages/Recharge/Recharge'
				})
			},
			LinkWithdrawal() {
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				
				uni.navigateTo({
					url: '/pages/Withdrawal/Withdrawal'
				})
			},
			Linkwallet() {
				if(!uni.getStorageSync('token')){
					uni.showToast({
						title: '请登录后操作',
						icon: 'none',
						duration: 1500
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/login/login'
						})
					},1500)
					return
				}
				
				uni.navigateTo({
					url: '/pages/wallet/wallet'
				})
			}
		}
	}
</script>

<style lang="scss">
	.my {
		width: 100vw;
		min-height: 100vh;
		float: left;

		.my_top {
			width: 100%;
			height: 457rpx;
			background: linear-gradient(180deg, #FFE9D4 0%, #FFFFFF 100%);
			position: relative;

			.my_top_info {
				width: 690rpx;
				height: 100rpx;
				position: absolute;
				left: 50%;
				top: 200rpx;
				transform: translate(-50%, 0);
				z-index: 9;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.my_top_info_src {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 20rpx;
				}

				.my_top_info_tet {
					width: 540rpx;
					height: 100%;
				}

				.my_top_info_tet>view {
					width: 100%;
					height: 50%;
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 40rpx;
					color: #333333;
				}

				.ID,
				.JF {
					max-width: 184rpx;
					min-width: 10rpx;
					height: 38rpx;
					background: #ffece1;
					border-radius: 8rpx;
					border: 2rpx solid #FE532B;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #FE532B;
					margin-right: 16rpx;
					text-align: center;
					line-height: 38rpx;
					padding-left: 6rpx;
					padding-right: 6rpx;
				}

				.JF {
					margin-right: 0;
				}
			}

			.my_top_info>view:nth-child(1) {}

			.my_top_info>view:nth-child(2) {
				width: 15rpx;
				height: 23rpx;
				margin-right: 15rpx;
			}
		}

		.my_bto {
			width: 690rpx;
			height: 160rpx;
			background: linear-gradient(270deg, #FE4624 0%, #FF8143 100%);
			border-radius: 20rpx;
			position: absolute;
			left: 50%;
			top: 330rpx;
			transform: translate(-50%, 0);
			z-index: 5;
			float: left;

			.my_bto_one {
				width: 90%;
				height: 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 29rpx auto 0;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #FFFFFF;
			}

			.my_bto_one_icon {
				width: 24rpx;
				height: 24rpx;
				margin-left: 15rpx;
			}

			.my_bto_two {
				width: 90%;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #FFF0C1;
				font-size: 50rpx;
				font-weight: bold;
				margin: 22rpx auto 0;

				.my_bto_two_btn {
					width: 116rpx;
					height: 60rpx;
					border-radius: 40rpx;
					border: 2rpx solid #FBE1B0;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 28rpx;
					color: #FBE1B0;
					margin-left: 20rpx;
					text-align: center;
					line-height: 60rpx;
				}
			}


		}

		.my_box {
			width: 100%;
			padding-top: 70rpx;
			padding-bottom: 80rpx;

			.my_box_hb {
				width: 690rpx;
				height: 112rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 3rpx 25rpx 0rpx rgba(88, 64, 64, 0.09);
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 0 auto;

				.my_box_hb_box {
					width: 630rpx;
					height: 52rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

				}

				.my_box_hb_box>view:nth-child(1),
				.my_box_hb_box>view:nth-child(2) {
					width: 50%;
					height: 100%;
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #000000;
				}

				.my_box_hb_box>view:nth-child(2) {
					justify-content: flex-end;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #333333;
				}

				.my_box_hb_box_hb {
					width: 52rpx;
					height: 52rpx;
					margin-right: 10rpx;
					text-align: center;
					line-height: 52rpx;
				}

				.my_box_hb_box_hb1 {
					width: 17rpx;
					height: 23rpx;
					text-align: center;
					line-height: 23rpx;
					margin-left: 10rpx;

				}
			}


			.my_box_dian {
				width: 690rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 3rpx 25rpx 0rpx rgba(88, 64, 64, 0.09);
				border-radius: 20rpx;
				margin: 25rpx auto 0;
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.my_box_dian_list {
					width: 630rpx;
					height: 52rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 55rpx auto 0;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #000000;

					.my_box_dian_list_src {
						width: 52rpx;
						height: 52rpx;
						margin-right: 20rpx;
						text-align: center;
						line-height: 52rpx;
					}
				}

				.my_box_dian_list>view:nth-child(1) {
					width: 80%;
					height: 100%;
					display: flex;
					align-items: center;
				}

				.my_box_dian_list>view:nth-child(2) {
					width: 17rpx;
					height: 23rpx;
					text-align: center;
					line-height: 23rpx;
				}

				.my_box_dian_men {
					width: 630rpx;
					height: 54rpx;
					margin: 0 auto;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.my_box_dian_men>view:nth-child(1) {
					width: 70%;
					height: 100%;
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #000000;
				}

				.my_box_dian_men>view:nth-child(2) {
					width: 30%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #FE4825;
				}

				.my_box_dian_men_src {
					width: 54rpx;
					height: 54rpx;
					border-radius: 50%;
					overflow: hidden;
					margin-right: 10rpx;
				}

				.my_box_dian_men_xian {
					width: 158rpx;
					height: 38rpx;
					background: #FFF3EE;
					border-radius: 8rpx;
					border: 2rpx solid #FE532B;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 800;
					font-size: 26rpx;
					color: #FE532B;
					margin-left: 15rpx;
				}

				.my_box_dian_men_xian>view:nth-child(1) {
					width: 23rpx;
					height: 23rpx;
					margin-right: 6rpx;
					text-align: center;
					line-height: 23rpx;
				}

				.my_box_dian_men_right {
					width: 17rpx;
					height: 23rpx;
					text-align: center;
					line-height: 23rpx;
					margin-left: 10rpx;
				}

				.my_box_dian_two {
					width: 630rpx;
					height: 44rpx;
					background-color: #F7F7F7;
					border-radius: 10rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 20rpx auto 0;
				}

				.my_box_dian_two>view:nth-child(1),
				.my_box_dian_two>view:nth-child(2) {
					width: 50%;
					height: 100%;
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #333333;
					margin-left: 8rpx;
				}

				.my_box_dian_two>view:nth-child(2) {
					justify-content: flex-end;
					margin-right: 8rpx;
					margin-left: 0;
				}

				.my_box_dian_therr {
					width: 630rpx;
					height: 40rpx;
					margin: 45rpx auto 0;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 28rpx;
					color: #333333;
				}
			}
		}
	}
</style>